package com.hnqcgczy.supplier.service.impl;

import com.hnqcgczy.supplier.dao.ShareholderDao;
import com.hnqcgczy.supplier.dao.impl.ShareholderDaoImpl;
import com.hnqcgczy.supplier.db.MyTransaction;
import com.hnqcgczy.supplier.service.ShareholderService;
import com.hnqcgczy.supplier.vo.Shareholder;

import java.sql.SQLException;
import java.util.List;

public class ShareholderServiceImpl implements ShareholderService {
    private MyTransaction myTransaction = new MyTransaction(true);
    private ShareholderDao shareholderDao = new ShareholderDaoImpl(myTransaction);

    @Override
    public boolean add(Shareholder shareholder) throws SQLException {
        return shareholderDao.add(shareholder) > 0;
    }

    @Override
    public boolean update(Shareholder shareholder) throws SQLException {
        return shareholderDao.update(shareholder) > 0;
    }

    @Override
    public boolean delete(Integer shareholderId) throws SQLException {
        return shareholderDao.delete(shareholderId) > 0;
    }

    @Override
    public Shareholder findOne(Integer shareholderId) throws SQLException {
        return shareholderDao.findOne(shareholderId);
    }

    @Override
    public List<Shareholder> findByLike(Shareholder shareholder, int pageNow, int pageSize) throws SQLException {

        int start = (pageNow - 1) * pageSize;

        return shareholderDao.findByLike(shareholder, start, pageSize);
    }

    @Override
    public int totals(Shareholder shareholder) throws SQLException {
        return shareholderDao.totals(shareholder);
    }
}
